<!DOCTYPE html>
<html>
<head>
  <meta charset="UTF-8">
  <!-- import CSS -->
  <link rel="stylesheet" href="https://cdn.staticfile.org/element-ui/2.15.9/theme-chalk/index.css">
</head>
<body>
<div id="app">
  <h1>{{weibo.nickname}}:{{weibo.content}}</h1>
  <p>发布于：{{weibo.created}}</p>
  <img v-for="url in weibo.urls.split(',')" :src="url" width="200">
  <hr>
  <input type="text" placeholder="评论内容..." v-model="comment.content">
  <input type="button" value="发评论" @click="insert()">
  <div v-for="c in arr">
    <h4>{{c.nickname}}评论说：{{c.content}}</h4>
    <p style="font-size: 12px">发布于：{{c.created}}</p>
  </div>
</div>
</body>
<script src="https://cdn.bootcdn.net/ajax/libs/axios/0.21.1/axios.min.js"></script>
<!-- import Vue before Element -->
<script src="https://cdn.staticfile.org/vue/2.6.14/vue.min.js"></script>
<!-- import JavaScript -->
<script src="https://cdn.staticfile.org/element-ui/2.15.9/index.min.js"></script>
<script>
 let v = new Vue({
    el: '#app',
    data: function() {
      return {
        weibo:{urls:""},
        comment:{},
        arr:[]
      }
    },
   methods:{
      insert(){
        v.comment.weiboId = v.weibo.id;
        axios.post("/comment/insert",v.comment).then(function (response) {
          if(response.data==1){
            location.reload();
          }else{
            alert("请先登录");
            location.href="/login.html";
          }
        })
      }
   },
   created:function () {
     axios.get("/weibo/selectById"+location.search).then(function (response){
       v.weibo = response.data;
     })
     axios.get("/comment/select"+location.search).then(function (response) {
       v.arr = response.data;
     })
   }
  })
</script>
</html>